local skel = fk.CreateSkill {
  name = "emo__xieji",
  tags = {Skill.Limited},
}

Fk:loadTranslationTable{
  ["emo__xieji"] = "邪祭",
  [":emo__xieji"] = "限定技，出牌阶段，你可以扣减1点体力上限，令一名其他角色复活为体力上限为3的随机恶魔。",

  ["#emo__xieji"] = "邪祭：减1点体力上限，将一名其他角色复活为恶魔。",
  ["#emo__xieji_revive"] = "复活 %arg(%arg2)",

  ["$emo__xieji1"] = "不死不灭，无尽的邪恶，降临这世间！",
  ["$emo__xieji2"] = "祭品充足……远古之厄，为我所用！",
}

skel:addEffect("active", {
  card_num = 0,
  target_num = 0,
  prompt = "#emo__xieji",
  interaction = function (self, player)
    local choices = {}
    for _, p in ipairs(Fk:currentRoom().players) do
      if p.dead and p.rest == 0 and p ~= player then
        table.insert(choices, "#emo__xieji_revive:::seat#"..p.seat..":"..p.general)
      end
    end
    if #choices == 0 then return end
    return UI.ComboBox {choices = choices}
  end,
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and table.find(Fk:currentRoom().players, function (p)
      return p.dead and p.rest == 0 and p ~= player
    end)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local seat = tonumber(string.sub(self.interaction.data:split(":")[4], 6))
    local p = table.find(room.players, function(p) return p.seat == seat end)
    if not p then return end
    room:changeMaxHp(player, -1)
    room:doIndicate(player, {p})
    local all = {"moe__asimode","moe__beiliya","moe__biexibu","moe__liweitan","moe__luxifa","moe__meifeisite","moe__sadan"}
    all = table.filter(all, function(g) return Fk.generals[g] ~= nil end)
    if #all == 0 then return end
    room:changeHero(p, "", false, true, false, false, false) -- 把副将清空
    room:changeHero(p, table.random(all), false, false, true)
    room:revivePlayer(p, true, self.name)
    p:drawCards(3, self.name)
  end,
})

return skel
